package com.atguigu.demo;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/8/10
 */
public class CyclicBarrierDemo2 {
    public static final int NUMBER = 7;

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(NUMBER);

        for (int i = 1; i <= NUMBER; i++) {
            new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + "----comes in");
                    // 先到的人，先等着
                    cyclicBarrier.await();
                    System.out.println(Thread.currentThread().getName() + "----开会");
                } catch (InterruptedException | BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }, String.valueOf(i)).start();
        }
    }
}
